package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.InvestmentReturnData;
import org.example.mapper.InvestmentReturnDataMapper;
import org.example.service.InvestmentReturnDataService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 投资收益率数据表Service实现类
 */
@Service
public class InvestmentReturnDataServiceImpl extends ServiceImpl<InvestmentReturnDataMapper, InvestmentReturnData> 
        implements InvestmentReturnDataService {
    
    @Override
    public int batchSave(List<InvestmentReturnData> dataList) {
        if (dataList == null || dataList.isEmpty()) {
            return 0;
        }
        
        // 使用MyBatis Plus的批量保存
        return this.saveBatch(dataList) ? dataList.size() : 0;
    }
    
    @Override
    public List<InvestmentReturnData> getByCategoryType(String categoryType) {
        LambdaQueryWrapper<InvestmentReturnData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InvestmentReturnData::getCategoryType, categoryType)
               .orderByAsc(InvestmentReturnData::getPeriodDate);
        return this.list(wrapper);
    }
    
    @Override
    public int clearByCategoryType(String categoryType) {
        LambdaQueryWrapper<InvestmentReturnData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InvestmentReturnData::getCategoryType, categoryType);
        return this.baseMapper.delete(wrapper);
    }
}
